home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50b Issue 142 (CD142b) (August 1998).iso / full / nt / MSSql / I386 / sqlx86.exe / PTK / SAMPLES / OLEAUTO / LOOPBACK.DAO / LOOPDAO.SQL < prev    next >
Encoding:
Text File  |  1996-04-03  |  1.7 KB  |  62 lines

  1. /* Stored Procedure:    sp_loopbackDAO
  2. ** Description:    This sp connects back to SQL Server via an OLE Automation
  3. **        object outside SQL Server.  The OLE Automation server retrieves a
  4. **        result set from a SQL Server table and returns it back
  5. **        to this stored procedure.
  6. **
  7. ** This sample script should be run in the context of the 'pubs' database,
  8. **  after creating the OLE DLL file using the SqlDao Visual Basic project
  9. */
  10.  
  11. if exists (select * from sysobjects where id = object_id('dbo.sp_loopbackDAO') and sysstat & 0xf = 4)
  12.     drop proc sp_loopbackDAO
  13. go
  14.  
  15.  
  16. create proc sp_loopbackDAO
  17.     @table_name varchar(30),
  18.     @field_name varchar(30)
  19. as
  20.     declare @pObj int, @hr int
  21.     declare @token varchar(255), @result varchar(255)
  22.  
  23.     Print 'Sample LoopbackDAO'
  24.     Print '------------------'
  25.  
  26.     /* Create a new OLE automation object */
  27.     exec @hr=sp_OACreate 'SQLDAO.CSqlDao', @pObj OUT
  28.  
  29.     /* Get the current client session token */
  30.     exec sp_getbindtoken @token OUT, 1
  31.  
  32.     BEGIN TRANSACTION
  33.         Print ' '
  34.         /* This transaction proves that the two connections to the server
  35.         ** belonging to the same client do not deadlock each other, since
  36.         ** they are 'bound' to each other; hence the redundant update statement
  37.         */
  38.  
  39.         exec ("update " + @table_name + " set " + @field_name + " = " + @field_name)
  40.  
  41.         Print ' '
  42.  
  43.         /* Invoke the DaoGetAuthors method in the CSQLDao obj */
  44.         exec @hr=sp_OAMethod @pObj, "DaoGetData", @result OUT, @table_name, @token
  45.         if @hr <> 0
  46.         BEGIN
  47.             ROLLBACK TRANSACTION
  48.         END
  49.  
  50.     COMMIT TRANSACTION
  51.  
  52.     /* Destroy the OLE Automation object */
  53.     exec sp_OADestroy @pObj
  54. go
  55.  
  56.  
  57.  
  58. /* Call the stored procedure created above */
  59.  
  60. sp_loopbackDAO authors, au_lname
  61. go
  62.